<template>
  <el-dialog 
    class="simple-dialog"
    title="生成卡号"
    :visible.sync="tempVisible"
    width="400px"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
    @close="close"
  >
    <el-form ref="formName" :rules="rules" :model="tempData" label-width="100px">
      <el-form-item label="生成数量:" prop="num">
        <el-input v-model="tempData.num" type='number'/>
      </el-form-item>
      <el-form-item label="期限:" prop="term">
        <el-input v-model="tempData.term" type='number'>
          <template slot="append">年</template>
        </el-input>
      </el-form-item> 
    </el-form>
    <span slot="footer" class="dalog-footer">
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="saveUpdate('formName')" :loading="submitLoading">保存</el-button>
    </span>
  </el-dialog>
</template>

<script> 
  import cardApi from '@/api/system/card'
  import testsApi from '@/api/system/publisher'
  export default {
    name: 'pubilsherAddEdit',
    props: {
      dialogVisible: {
        type: Boolean,
        default: false
      },
      data: {
        type: Object,
        default: {}
      }
    },
    data() {
      return {
        submitLoading:false,
        tempVisible: false,
        projectLeave:0,
        tempData: {
          id: null
        },
        rules: {
          num: [{ required: true, message: '请输入数量', trigger: 'blur' }],
          term: [{ required: true, message: '请输入期限', trigger: 'blur' }],
        },
        areaInfo:[]
      }
    },
    watch: {
      dialogVisible: function(val) {
        this.tempVisible = val;
      },
      data: function(val) {
        this.tempData = JSON.parse(JSON.stringify(val));
      }
    },
    mounted() {
    },
    methods: {
      close() {
        this.$refs['formName'].clearValidate()
        this.$emit('close')
      },
      saveUpdate(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.submitLoading = true;
            this.tempData.publistherId = this.tempData.id;
            cardApi.save(this.tempData).then(res => {
              this.$message.success('生成成功')
              this.close()
              this.$emit('reloadTable',res.data)
              this.submitLoading = false;
            }).catch(() => {})
          } else {
            return false
          }
        })
      }
    }
  }
</script>

<style lang="scss">

</style>
